<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="css/index.css">
    <script src="js/vue.js"></script>
    <script src="js/elementui.js"></script>
    <script src="js/axios.js"></script>
    <script src="js/common.js"></script>
    <title>登录</title>
</head>
<style>
    body {
        margin: 0px;
        background-color: #fce8e8;
    }

    #all-from {
        width: 30%;
        margin: 150px;
        background-color: #b6f4fa;
        border-radius: 10px;
        box-shadow: 0 0 10px #acd8fa;
        padding: 90px;
        text-align: center;
        margin-left: 450px;
    }
</style>

<body>
    <div id="app">
        <div id="all-from">
            <h2>登录</h2>
            <el-form :model="form" label-width="80px">
                <el-form-item label="用户名">
                    <el-input v-model="form.uname"></el-input>
                </el-form-item>
                <el-form-item label="密码">
                    <el-input type="password" v-model="form.upwd"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="onSubmit">登录</el-button>
                    <el-button>取消</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</body>
<script>
    new Vue({
        el: "#app",
        data: {
            form: {
                uname: "",
                upwd: "",
            }

        },
        methods: {
            onSubmit() {
                let that = this
                axios.post(API + "boot/userregister", this.form).then(function (res) {
                    // alert(JSON.stringify(res))
                    if (res.data.code === 200) {
                        let token = res.data.data.token
                        //把token存到本地
                        window.localStorage.setItem("token", token)
                        window.location.href = "menu.html"
                    } else {
                        that.$message("登录失败");
                    }
                }).catch(err => {
                    console.log(err)
                });
                // axios.post("http://localhost:8080/boot/userlogin", this.form)
                //     .then((res) => {
                //         console.log(res);
                //         if (res.data.code === 200) {
                //             this.$message({
                //                 message: '登录成功',
                //                 type: 'success'
                //             });
                //             setTimeout(() => {
                //                 window.location.href = "menu.html";
                //             }, 1500); // 延迟1.5秒
                //         } else {
                //             this.$message({
                //                 message: res.data.message || '登录失败',
                //                 type: 'error'
                //             });
                //         }
                //     })
                //     .catch((error) => {
                //         console.error('There was an error!', error);
                //         this.$message({
                //             message: '请求失败，请稍后再试',
                //             type: 'error'
                //         });
                //     });
            }

        }
    })
</script>

</html>